<?php

namespace App\Http\Requests\administration;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait RecordRequest
{
    public static function enter_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'price' => 'required',
            'number' => 'required',
            'operation_time' => 'required',
        ], [
            'price.required' => '请填写单价',
            'number.required' => '请填写数量',
            'operation_time.required' => '请填写购买日期',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function out_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'take_user' => 'required',
            'number' => 'required',
            'operation_time' => 'required',
        ], [
            'take_user.required' => '请填写领用人员',
            'number.required' => '请填写数量',
            'operation_time.required' => '请填写领用日期',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
